//
//  ViewController.m
//  UIKIit_APPS
//
//  Created by 李竞 on 16/1/25.
//  Copyright © 2016年 lionjing. All rights reserved.
//

#import "ViewController.h"
#import "LJ_App_View.h"

//第一种方式所需要宏 -------------------------------------------|
#define kAppView_W 90                              //App的宽度|
#define kAppView_H 120                              //App的高度|
#define KAppView_Count_Row 3                       //App行个数|
#define kAppView_Count_Que 4                       //App列个数|
#define kScreen_W [UIScreen mainScreen].bounds.size.width  //|
#define KsCreen_H [UIScreen mainScreen].bounds.size.height //|
//-----------------------------------------------------------|

@interface ViewController ()<LJ_App_View_Delegate>

@property (nonatomic , strong) NSMutableArray *array_Apps_M ;

@end

@implementation ViewController
-(NSMutableArray *)array_Apps_M{
    if (!_array_Apps_M) {
        NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"app.plist" ofType:nil]];
        _array_Apps_M = [NSMutableArray arrayWithCapacity:array.count];
        for (NSDictionary *dict in array) {
            LJ_App_Model *app_Model = [LJ_App_Model initWith_Dict:dict];
            [_array_Apps_M addObject:app_Model];
        }

    }
    return _array_Apps_M;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //第一种方式 :
    [self function_one];
}

-(void)function_one{
//    行间隙:
    CGFloat margin_X = ( kScreen_W - KAppView_Count_Row * kAppView_W ) / (KAppView_Count_Row + 1) ;
//    列间隙:
    CGFloat margin_Y = ( KsCreen_H - kAppView_Count_Que * kAppView_H ) / (kAppView_Count_Que + 1) ;

    for (int i = 0; i < self.array_Apps_M.count; i++) {
        ///行 :0,1,2=>0 ; 3,4,5=>1 ; 6,7,8=>2 ;
        int Row = i / KAppView_Count_Row ;
        ///列 :0,3,6=>0 ; 1,4,7=>1 ; 2,5,8=>2 ;
        int Col = i % KAppView_Count_Row ;

        ///坐标:
        float X = Col * ( kAppView_W + margin_X ) + margin_X ;
        float Y = Row * ( kAppView_H + margin_Y ) + margin_Y ;

//        CGRect rect = CGRectMake(X, Y, kAppView_W, kAppView_H);
//        LJ_App_View *appView = [LJ_App_View init_With_Frame_:rect and_Model:self.array_Apps_M[i]];

///创建,并添加 :
        LJ_App_View *appView = [[LJ_App_View alloc]initWithFrame:CGRectMake(X, Y, kAppView_W, kAppView_H)] ;
        appView.backgroundColor = [UIColor whiteColor];
        
        appView.app_Model = self.array_Apps_M[i];

        appView.delegate = self ;

        [self.view addSubview:appView];

    }
}
-(void)Do_After_Btn_Clicked:(UIButton *)button {

    UILabel *label = [[UILabel alloc]init];
    label.text = @"正在下载中...";
    label.alpha = 0.0;
    label.font = [UIFont systemFontOfSize:7.0];
    [label sizeToFit];
    label.center = self.view.center ;
    label.backgroundColor = [UIColor darkGrayColor];
    [self.view addSubview:label];

[UIView animateWithDuration:3.0 animations:^{

    label.alpha = 1.0;
    label.font = [UIFont systemFontOfSize:15.0];
    [label sizeToFit];


} completion:^(BOOL finished) {

    [label removeFromSuperview];

}];


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

}

@end
